package com.app.controller;

import com.app.bean.dto.UserDto;
import com.app.bean.vo.LoginBean;
import com.app.bean.vo.LoginResult;
import com.app.common.BaseVo;
import com.app.entity.User;
import com.app.enums.SystemAllSourceEnums;
import com.app.service.IUserService;
import com.app.service.InnerCommand;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @autor xiaoyu.fang
 * @date 2019/10/12 11:25
 */
@RestController
@RequestMapping("/sys")
public class SysController {

    @Autowired
    private IUserService userService;

    /**
     * 用户小程序登录
     *
     * @param loginBean
     * @return
     */
    @PostMapping("/login")
    public BaseVo login(@RequestBody LoginBean loginBean) {
        LoginResult result = userService.findByCode(loginBean);
        return new BaseVo(result);
    }

    /**
     * 获取用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/user/{id}/detail")
    public User getUserById(@PathVariable("id") ObjectId id) {
        return userService.findById(id);
    }

    /**
     * @return
     */
    @GetMapping("/user/addBusiness")
    public BaseVo addBusiness() {
        User user = new User();
        user.setNickName("李四23333");
        userService.addBusiness(user);
        return new BaseVo();
    }

    @GetMapping("/user/testBloomFilter")
    public BaseVo testBloomFilter(@RequestParam("value") String value) {
        userService.testBloomFilter(value);
        return new BaseVo();
    }

    @PostMapping("/inner/commond")
    public BaseVo innerCommond(@RequestBody UserDto userDto) {
        InnerCommand innerCommand = SystemAllSourceEnums.getByValue(userDto.getUserSource()).getClassBySource();
        UserDto userDto1 = innerCommand.syncCheck(userDto);
        return new BaseVo(userDto1);
    }
}
